这是一个C#开发的抽奖程序,程序可以根据用户自己的需求修改抽奖名单和抽奖奖项,同时程序还生成中奖名单文件!
如果你要指定抽奖名单,你只需要修改Index.aspx页面下updateRndNum()函数中的name,
将其替换成你的名单即可!
如果需要修改中奖类型,修改HTML代码中的奖项即可!
抽奖程序同时可以产生抽奖名单文件,文件存放位置在D盘根目录!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="ChouJiang.Index" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>华正集团2017年度抽奖</title> <style type="text/css"> .body { text-align: center; padding-top: 50px; } #body { background: url(./bj.jpg); } #Result { width: auto; min-width: 220px; max-width: 1200px; height: auto; display: inline-block !important; border: 3px solid #40AA53; padding: 50px; background: #efe; margin: 0 auto; text-align: center; color: #40AA53; font-size: 50px; } .ResultNum { font-size: 40pt; font-family: Verdana; width: 170px; margin-left: 10px; display: block; float: left; } #Button { margin: 50px 0 0 0; } #Button input { font-size: 40px; padding: 0 50px; } #btn { background-color: #40AA53; border: 1px solid #40AA53; width: 20%; height: 60px; margin: 0em auto; font-size: 1em; border-radius: 2.5px; -moz-border-radius: 2.5px; -webkit-border-radius: 2.5px; color: #FFF; } </style> <link href="bootstrap/bootstrap.min.css" rel="stylesheet" /></head><body id="body"> <div class="form-horizontal"> <div style="margin-top: 8px;"> <label class="col-md-2 control-label">本次抽奖人数:</label> <div> <input type="text" value="1" style="width: 200px; background-color: #D67064; display: inline;" class="form-control" name="pCount" id="pCount" placeholder="请输入本次需要抽奖的人数" /> </div> </div> <div> <label class="col-md-2 control-label">选择奖项:</label> <div> <select name="jxType" id="jxType" class="form-control" style="width: 100px; background-color: #D67064; display: inline;"> <option value="一等奖">一等奖</option> <option value="二等奖">二等奖</option> <option value="三等奖">三等奖</option> <option value="四等奖">四等奖</option> <option value="五等奖">五等奖</option> </select> </div> </div> <div class="col-md-10 col-md-offset-2"> <button type="button" class="btn btn-success" style="background-color: #B4A13A; display: inline;" onclick="setting()">确定</button> </div> </div> <div class="body"> <div id="Button"> <input type='button' id="btn" value='开始' onclick='beginRndNum(this)' /> </div> <h1 style="color: #40AA53">抽奖结果</h1> <div id="Result" style="color: #40AA53"> <span id="ResultNum" class="ResultNum">0</span> </div> </div> <div id="view" style="text-align: left; color: red; margin: 40px; font: normal 14px/24px 'MicroSoft YaHei';"> </div></body></html><script type="text/javascript" src="js/jquery-1.7.2.min.js"></script><script type="text/javascript" src="bootstrap/bootstrap.min.js"></script><script type="text/javascript"> var count = 0; var type = 0; var g_Interval = 1; var g_Timer; var running = false; var str = ""; var jsons = ""; var temp = []; //temp存放生成的随机数组 var typelist = []; //存放已出现的获奖类型 function setting() { count = $("#pCount").val(); type = $("#jxType").val(); var htmlStr = []; for (var i = 0; i < count; i ) { htmlStr.push("<span id=\"ResultNum" i "\" class=\"ResultNum\">" i "</span>"); } $("#Result").text(""); $("#Result").append(htmlStr.join("")); } function beginRndNum(trigger) { if ($.inArray(type, typelist) > -1) str = " "; else str = type ": "; if (running) { running = false; clearTimeout(g_Timer); $(trigger).val("开始"); $('.ResultNum').css('color', 'red'); for (n = 0; n < count; n ) { str = $('#ResultNum' n).html() " "; temp.push($('#ResultNum' n).html()); //获取arr[num]并放入temp typelist.push(type); } //写文件 $.ajax({ async: false, url: "./Handler.ashx?action=set&str=" str, context: str, postData: str, success: function () { $(this).addClass("done"); } }); //读文件 $.get("./Handler.ashx", { action: "get" }, function (data) { alert(document.getElementById("view").innerHTML = data); }); } else { running = true; $('.ResultNum').css('color', 'black'); $(trigger).val("停止"); beginTimer(); } } function updateRndNum() { var name = ["001","002","003","004","005","006","007","008","009"]; //合并两个数组 var result = []; for (var i = 0; i < name.length; i ) { var na = name[i]; var isExist = false; for (var j = 0; j < temp.length; j ) { var te = temp[j]; if (na == te) { isExist = true; break; } } if (!isExist) { result.push(na); } } for (i = 0; i < count; i ) { // var n = Math.floor(Math.random() * name.length 1) - 1; var n = Math.floor(Math.random() * result.length); $('#ResultNum' i).html(result[n]); result.splice(n, 1); } } function beginTimer() { g_Timer = setTimeout(beat, g_Interval); } function beat() { g_Timer = setTimeout(beat, g_Interval); updateRndNum(); }</script>
评论